﻿using System;
using System.Xml;

namespace Controler
{
    public class XmlHelper
    {
        XmlDocument _Doc;
        string _XmlPath = "Setting.xml";

        XmlElement _Root;
        public XmlHelper()
        {
            _Doc = new XmlDocument();
            _Doc.Load($"{AppDomain.CurrentDomain.BaseDirectory}Setting.xml");
            _Root = _Doc.DocumentElement;
        }

        public string Read(Setting setting)
        => _Root.GetElementsByTagName(setting.ToString())[0].InnerText;

        public void Write(Setting setting, string value)
        {
            _Root.GetElementsByTagName(setting.ToString())[0].InnerText = value;
            _Doc.Save(_XmlPath);
        }
    }

    public enum Setting
    {
        SaveImgPath,
        ServiceCron,
        BingUrl,
        ImgRegex,
        ImgType
    }
}
